﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace LotteCinema.Admin
{
    public partial class XemThongTin : System.Web.UI.Page
    {
        BUS.BXemThongTin bxtt = new BUS.BXemThongTin();
        BUS.BNhanVien bnv = new BUS.BNhanVien();
        DAO.CNhanVien cnv = new DAO.CNhanVien();
        static DataTable dt;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlgioitinh.Items.Add("Nam");
                ddlgioitinh.Items.Add("Nữ");
                dt = bxtt.NHANVIEN_TimKiemTheoMa(Session["TENDANGNHAP"].ToString());
                lbhoten.Text= dt.Rows[0][2].ToString();
                lbcmnd.Text=dt.Rows[0][3].ToString();
                lbngaysinh.Text = Convert.ToDateTime(dt.Rows[0][4].ToString()).ToShortDateString().ToString();
                lbgioitinh.Text=dt.Rows[0][5].ToString()=="True"?"Nam":"Nữ";
                lbdiachi.Text=dt.Rows[0][6].ToString();
                lbdienthoai.Text=dt.Rows[0][7].ToString();
                lbchucvu.Text=dt.Rows[0][9].ToString();
                pnthongtin.Visible = true;
                pncapnhat.Visible = false;
            }
        }

        protected void khoitaocontrol()
        {
            txthoten.Text = "";
            txtcmnd.Text = "";
            txtngaysinh.Text = "";
            txtdiachi.Text = "";
            txtdienthoai.Text = "";
        }
        protected void capnhatthongtin()
        {
            dt = bxtt.NHANVIEN_TimKiemTheoMa(Session["TENDANGNHAP"].ToString());
            lbhoten.Text = dt.Rows[0][2].ToString();
            lbcmnd.Text = dt.Rows[0][3].ToString();
            lbngaysinh.Text = Convert.ToDateTime(dt.Rows[0][4].ToString()).ToShortDateString().ToString();
            lbgioitinh.Text = dt.Rows[0][5].ToString() == "True" ? "Nam" : "Nữ";
            lbdiachi.Text = dt.Rows[0][6].ToString();
            lbdienthoai.Text = dt.Rows[0][7].ToString();
            lbchucvu.Text = dt.Rows[0][9].ToString();
        }
        protected void lblThayDoiThongTin_Click(object sender, EventArgs e)
        {
           txthoten.Text=lbhoten.Text;
           txtcmnd.Text= lbcmnd.Text;
           txtngaysinh.Text= lbngaysinh.Text;
           int i=0;
           while (lbgioitinh.Text != ddlgioitinh.Items[i].Text)
           {
               i++;           
           };
           ddlgioitinh.Items[i].Selected = true;
           txtdiachi.Text= lbdiachi.Text;
           txtdienthoai.Text=lbdienthoai.Text;
            pnthongtin.Visible = false;
            pncapnhat.Visible = true;
        }

        protected void lblCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                cnv._manv = Session["TENDANGNHAP"].ToString();
                cnv._hoten = txthoten.Text;
                cnv._cmnd = txtcmnd.Text;
                cnv._ngaysinh = txtngaysinh.Text;
                cnv._gioitinh = ddlgioitinh.SelectedValue.ToString() == "Nam" ? "True" : "False";
                cnv._diachi = txtdiachi.Text;
                cnv._dienthoai = txtdienthoai.Text;
                bxtt.NHANVIEN_CapNhatThongTin(cnv);
                khoitaocontrol();
                DTO.WebMegBox.Show("Đã cập nhật thông tin thành công");
            }
            catch (Exception ex)
            {
                DTO.WebMegBox.Show("Lỗi hệ thống");
            }
        }

        protected void lblQuayLai_Click(object sender, EventArgs e)
        {
            khoitaocontrol();
            capnhatthongtin();
            pnthongtin.Visible = true;
            pncapnhat.Visible = false;
        }
    }
}